package com.zxy.activemqjms;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author zhangxuyuan
 * @version 1.0
 * @date 2020/11/22
 */
public class PTP_Producer {

    public static void main(String[] args) throws JMSException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");

        Connection connection = connectionFactory.createConnection();

        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Queue queue = session.createQueue("queue1");

        MessageProducer producer = session.createProducer(queue);



        for(int i=0;i<10;i++)
        {
            TextMessage hello_world = session.createTextMessage("hello world"+"------"+i);
            producer.send(hello_world);
            System.out.println("消息发送：" + hello_world.getText());
        }



        session.close();

        connection.close();

    }
}
